﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace DataVisualization.WindowsFormsApp
{
    public partial class FormStartup : Form
    {
        private Random _random;

        public FormStartup()
        {
            InitializeComponent();
            _random = new Random();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            chart1.Series.Clear();
            chart1.ChartAreas.Clear();
            chart1.Legends.Clear();
            chart1.ChartAreas.Add("ChartAreaColumn");
            chart1.ChartAreas.Add("ChartAreaPie");
            chart1.ChartAreas.Add("ChartAreaLine");
            chart1.ChartAreas.Add("Default");
            chart1.Legends.Add(new Legend("LegendColumn") { DockedToChartArea = "ChartAreaColumn", IsDockedInsideChartArea = false });
            chart1.Legends.Add(new Legend("LegendPie") { DockedToChartArea = "ChartAreaPie", IsDockedInsideChartArea = false });
            chart1.Legends.Add(new Legend("LegendLine") { DockedToChartArea = "ChartAreaLine", IsDockedInsideChartArea = false });
            chart1.Legends.Add("LegendDefault");

            var seriesColumn = new Series("Sales");
            seriesColumn.ChartType = SeriesChartType.Column;

            seriesColumn.Points.AddXY("Q1", _random.Next(300));
            seriesColumn.Points.AddXY("Q2", _random.Next(300));
            seriesColumn.Points.AddXY("Q3", _random.Next(300));
            seriesColumn.Points.AddXY("Q4", _random.Next(300));

            seriesColumn.Legend = "LegendColumn";
            seriesColumn.ChartArea = "ChartAreaColumn";
            chart1.Series.Add(seriesColumn);

            var seriesColumn1 = new Series("Sales1");
            seriesColumn1.ChartType = SeriesChartType.Column;

            seriesColumn1.Points.AddXY("Q1", _random.Next(300));
            seriesColumn1.Points.AddXY("Q2", _random.Next(300));
            seriesColumn1.Points.AddXY("Q3", _random.Next(300));
            seriesColumn1.Points.AddXY("Q4", _random.Next(300));

            seriesColumn1.Legend = "LegendColumn";
            seriesColumn1.ChartArea = "ChartAreaColumn";
            chart1.Series.Add(seriesColumn1);

            var seriesPie = new Series("Distribution");
            seriesPie.ChartType = SeriesChartType.Pie;

            seriesPie.Points.AddXY("A", _random.Next(300));
            seriesPie.Points.AddXY("B", _random.Next(300));
            seriesPie.Points.AddXY("C", _random.Next(300));

            seriesPie.Legend = "LegendPie";
            seriesPie.ChartArea = "ChartAreaPie";
            chart1.Series.Add(seriesPie);

            var seriesLine = new Series("Trend");
            seriesLine.ChartType = SeriesChartType.Line;

            seriesLine.Points.AddXY(1, _random.Next(300));
            seriesLine.Points.AddXY(2, _random.Next(300));
            seriesLine.Points.AddXY(3, _random.Next(300));
            seriesLine.Points.AddXY(4, _random.Next(300));

            seriesLine.Legend = "LegendLine";
            seriesLine.ChartArea = "ChartAreaLine";
            chart1.Series.Add(seriesLine);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            chart1.SaveImage("test.png", ChartImageFormat.Png);
        }
    }
}
